<script setup>
    import { sdCityList } from '@/utils/index'
    import { ElMessage } from 'element-plus'
    import { placementAdd, placementEdit } from '@/common/apis'
    import FormList from '@/components/FormList.vue'

    const emit = defineEmits(['addSuccess'])

    let dialogVisible = $ref(false)
    let form = $ref({})

    let showType = $ref('')

    const showAddDialog = (data = {}, type) => {
        form = data
        showType = type
        dialogVisible = true
    }

    const formItem = [
        {
            label: '姓名',
            value: 'name',
        },
        {
            label: '人员类型',
            value: 'personGenre',
        },
        {
            label: '身份证号码',
            value: 'idCard',
        },
        {
            label: '设岗单位',
            value: 'monadName',
            type: 'select',
            selectData: ['济南市历下区姚家街道办事处社区服务中心']
        },
        {
            label: '用岗单位',
            value: 'useMonadName',
            type: 'select',
            selectData: ['济南市历下区姚家街道总工会']
        },
        {
            label: '岗位名称',
            value: 'postName',
        },{
            label: '岗位联系人',
            value: 'postContacts',
        },
        {
            label: '合同开始时间',
            value: 'contractStartTime',
            type: 'date'
        },
        {
            label: '合同终止时间',
            value: 'contractEndTime',
            type: 'date'
        }
    ]

    const changeForm = (v, data) => {
        form[v] = data
    }

    const handleClick = () => {

        ElMessage.success('操作成功~')
        dialogVisible = false
        
        // let api = placementAdd
        // if(form.id) api = placementEdit
        // api(form).then(res => {
        //     if(res.success){
        //         ElMessage.success('操作成功~')
        //         dialogVisible = false
        //         emit('addSuccess')
        //     }else{
        //         ElMessage.error(res.message)
        //     }
        // })
    }


    defineExpose({
        showAddDialog
    })

</script>

<template>
    <el-dialog
        v-model="dialogVisible"
        :title="showType == 'add' ? '新增' : showType =='edit' ? '修改' : '详情'"
        custom-class="zz-dialog"
        width="900px"
        v-if="dialogVisible"
    >	
        <form-list :list="formItem" :formData="form" :type="showType" @changeForm="changeForm"></form-list>

        <template #footer v-if="showType != 'details'">
            <span class="dialog-footer">
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" @click="handleClick">
                    确定
                </el-button>
        </span>
        </template>
    </el-dialog>
</template>
